package com.loan.web;

import com.alibaba.fastjson.JSON;
import com.loan.dal.entity.InCustomerDO;
import com.loan.dal.entity.InPhoneDO;
import com.loan.service.InCustomerService;
import com.loan.service.InPhoneService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * 注册页面
 */

@RestController
@RequestMapping("/json")
@Slf4j
public class ContinentJsonController {
    @Autowired
    private InCustomerService inCustomerService;

    @Autowired
    private InPhoneService inPhoneService;

    /**
     * 立即申请
     */
    @RequestMapping(value = "/add",method = RequestMethod.POST)
    public String addInCustomer(@RequestBody InCustomerDO inCustomerDO){
        InCustomerDO inCustomer =new InCustomerDO();
        inCustomer.setCustomerName(inCustomerDO.getCustomerName());
        inCustomer.setPhone(inCustomerDO.getPhone());
        inCustomerService.addInCustomers(inCustomer);
         log.debug("放回ID："+inCustomer.getId());
        log.debug("InCustomerDO : {}",inCustomer);
        String date = JSON.toJSONString(inCustomer.getId());
        return date;
    }

    /**
     * 验证信息
     */
    @RequestMapping(value = "/vod",method = RequestMethod.POST)
    public String vodInCustomer(@RequestBody Integer id){

       InCustomerDO inCustomerDO= inCustomerService.queryById(id);

        String date = JSON.toJSONString(inCustomerDO);
        return date;
    }

    /**
     * 客户信息采集
     */
    @RequestMapping(value = "/edit",method = RequestMethod.POST)
    public String editInCustomer(@RequestBody InCustomerDO inCustomerDO){

        inCustomerService.modifyCustomers(inCustomerDO);

        String date = JSON.toJSONString(inCustomerDO);
        return date;
    }


    /**
     * 客户信息采集
     */
    @RequestMapping(value = "/addphone",method = RequestMethod.POST)
    public String addInPhoneDO(@RequestBody InPhoneDO inPhoneDO){
        log.debug("我拉了：{}"+inPhoneDO.toString());
        inPhoneService.addPhoneDO(inPhoneDO);
        log.debug("放回ID："+inPhoneDO.getId());
        log.debug("InCustomerDO : {}",inPhoneDO);
        return JSON.toJSONString(inPhoneDO);
    }


}